package com.sdg.controller;

import com.sdg.services.APPService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class AppController {
		
	@Autowired
	private APPService appService;

	@RequestMapping(value = "/getPart1")
	public  List<Map<String,Object>> getCategorys(){
		List<Map<String,Object>> list = appService.getPart1();
		return list;
		
	}
	
//	@RequestMapping(value = "/getPart2")
//	public Map getTopRating(){
//		List<Map<String,Object>> list = appService.getPart2();
//		List key = new ArrayList();
//		List val = new ArrayList();
//		Map returnMap = new HashMap<String, List>();
//		for(Map<String,Object> m:list) {
//			key.add(m.get("name"));
//			val.add(m.get("val"));
//
//		}
//		returnMap.put("key", key);
//		returnMap.put("val", val);
//
//		return returnMap;
//	}
	
	@RequestMapping(value = "/getPart2")
	public Map getTopRating1(){
		
		List<Map<String,Object>> list = appService.getPart2();
		List key = new ArrayList();
		List val = new ArrayList();
		
		Map returnMap = new HashMap<String, List>();
		for(Map<String,Object> m:list) {
			key.add(m.get("name"));
			val.add(m.get("val"));
		
		}
		returnMap.put("key", key);
		returnMap.put("val", val);
		
		return returnMap;
	}

	@RequestMapping(value = "/chinaMap")
	public Map getChinaMap(){

		List<Map<String,Object>> list = appService.getChinaMap();
		List key = new ArrayList();
		List val = new ArrayList();

		Map returnMap = new HashMap<String, List>();
		for(Map<String,Object> m:list) {
			key.add(m.get("name").toString().trim());
			val.add(m.get("val"));

		}
		returnMap.put("key", key);
		returnMap.put("val", val);

		return returnMap;
	}


	
	@RequestMapping(value = "/getPart4")
	public Map getTopRating2(){
		
		List<Map<String,Object>> list = appService.getPart4();
		List key = new ArrayList();
		List val = new ArrayList();
		
		Map returnMap = new HashMap<String, List>();
		for(Map<String,Object> m:list) {
			key.add(m.get("name"));
			val.add(m.get("val"));
		
		}
		returnMap.put("key", key);
		returnMap.put("val", val);
		
		return returnMap;
	}
	@RequestMapping(value = "/getPart5")
	public  List<Map<String,Object>> getCategorys5(){
		List<Map<String,Object>> list = appService.getPart5();
		return list;

	}
}
